package com.start.captcha.web;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan({"com.start.captcha.web"})
@ConfigurationProperties(prefix = "start.captcha")
public class CaptchaAutoConfiguration {
    private String redisKey;
    private Integer expire;

    public void setExpire(Integer expire) {
        this.expire = expire;
    }

    public void setRedisKey(String redisKey) {
        this.redisKey = redisKey;
    }

    public String getRedisKey() {
        if (StringUtils.isEmpty(redisKey)) {
            return "start:captcha:";
        }
        if (redisKey.endsWith(":")) {
            return redisKey;
        }
        return redisKey + ":";
    }

    public Integer getExpire() {
        if (expire == null || expire < 1) {
            return 10;
        }
        return expire;
    }
}
